<?php
/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-26
 * Time: 14:59
 * @description: 同一种协议监听多端口
 * @Author: yfl
 * @QQ 554665488
 */
$server = new Swoole\Server('0.0.0.0', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$server->addlistener('127.0.0.1', 9502, SWOOLE_SOCK_TCP);

//固定包头跟包体协议
$server->set([
//    'open_length_check' => true,
//    'package_length_type' => 'N',
//    'package_length_offset' => 0, //计算总长度
//    'package_body_offset' => 4,//包体位置
//    'package_max_length' => 1024 * 1024 //总的请求数据大小字节为单位
]);

$server->on('connect', function ($serv, $fd) {
//    echo "有新的客户端连接，连接标识为$fd" . PHP_EOL;
});

$server->on('receive', function ($serv, $fd, $from_id, $data) {

         var_dump($serv->connection_info());
});

$server->on('close', function ($serv, $fd) {
//    echo "编号为{$fd}的客户端已经关闭." . PHP_EOL;
});


$server->start();